<template>
  <div>
    <a-card :bordered='false'>
      <f-search-form :more='true' @searchHandler='searchHandler' :tableObj='tableObj' :show-export-btn='true'
                     export-url='exportUrl2'>
        <f-search-form-item label='部门名称' ref='dept' name='deptId' type='select' valueKey='deptId' label-key='deptName'
                            style='width:220px' />
        <f-search-form-item label='订单编号' name='orderNo' style='width: 250px' />
        <f-search-form-item label='回款日期' name='orderNo' style='width: 250px' />
      </f-search-form>
      <f-table ref='table' rowKey='deptId' :showSetting='true' :tableColumns='columns' :scroll='{x:true}'
               :multiple='false' :operator='operator' :params='queryParam' :api='api.saleYearStatistic'
               handler='hyOrderStaticsListHandler'>
      </f-table>
    </a-card>
  </div>
</template>
<script>
import api from '../../js/api'

export default {
  name: 'ProfitTab2',
  components: {},
  data() {
    let me = this
    //操作按钮
    let operator = []
    let customFlag = this.$store.state.user.customFlag
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        // companyId:this.$store.state.user.companyId
        companyId: 100
      },
      tableObj: null,
      superAdmin: this.superAdmin,
      // 表头
      columns: [
        {
          title: '序号',
          width: '70px',
          align: 'center',
          fixed: 'left',
          customRender: (text, record, index) => index + 1
        },
        {
          title: '部门名称',
          align: 'left',
          width: '130px',
          dataIndex: 'deptName'
        },
        {
          title: (new Date().getFullYear() - 1) + '年',
          align: 'center',
          children: [
            {
              title: '1月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 1,
              key: (new Date().getFullYear() - 1) + '-' + 1,
              width: 100
            }, {
              title: '2月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 2,
              key: (new Date().getFullYear() - 1) + '-' + 2,
              width: 100
            }, {
              title: '3月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 3,
              key: (new Date().getFullYear() - 1) + '-' + 3,
              width: 100
            }, {
              title: '4月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 4,
              key: (new Date().getFullYear() - 1) + '-' + 4,
              width: 100
            }, {
              title: '5月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 5,
              key: (new Date().getFullYear() - 1) + '-' + 5,
              width: 100
            }, {
              title: '6月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 6,
              key: (new Date().getFullYear() - 1) + '-' + 6,
              width: 100
            }, {
              title: '7月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 7,
              key: (new Date().getFullYear() - 1) + '-' + 7,
              width: 100
            }, {
              title: '8月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 8,
              key: (new Date().getFullYear() - 1) + '-' + 8,
              width: 100
            }, {
              title: '9月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 9,
              key: (new Date().getFullYear() - 1) + '-' + 9,
              width: 100
            }, {
              title: '10月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 10,
              key: (new Date().getFullYear() - 1) + '-' + 10,
              width: 100
            }, {
              title: '11月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 11,
              key: (new Date().getFullYear() - 1) + '-' + 11,
              width: 100
            }, {
              title: '12月',
              dataIndex: (new Date().getFullYear() - 1) + '-' + 12,
              key: (new Date().getFullYear() - 1) + '-' + 12,
              width: 100
            }
          ]
        },
        {
          title: (new Date().getFullYear() - 1) + '年合计',
          align: 'left',
          width: '130px',
          dataIndex: 'lastTotal'
        },
        {
          title: '2023',
          align: 'center',
          children: [
            {
              title: '1月',
              dataIndex: 'building',
              key: 'building',
              width: 100
            }
          ]
        },
        {
          title: new Date().getFullYear() + '年合计',
          align: 'left',
          width: '130px',
          dataIndex: 'currentTotal'
        },
        {
          title: '总计',
          align: 'left',
          width: '130px',
          dataIndex: 'total'
        },
        {
          title: '环比',
          align: 'center',
          width: '130px',
          dataIndex: 'qoq'
        }, {
          title: '同比',
          align: 'center',
          width: '130px',
          dataIndex: 'yoy'
        }
      ],
      operator: operator
    }
  },
  created() {
    this.initHead()
  },
  mounted() {
    this.tableObj = this.$refs.table
  },
  methods: {
    initHead() {
      this.http.get(this, {
        url: this.api.saleYearStatistic.head,
        params: {},
        success: function(me, data) {
          me.columns[4].children = data
          console.log(me.columns)
          me.columns[4].title = new Date().getFullYear()
        }
      })
    }
  }
}
</script>
